package com.edu.test;

import com.edu.bean.Employee;
import com.edu.bean.EmployeeExample;
import com.edu.mapper.EmployeeMapper;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class MyTest02 {

    SqlSession sqlSession = null;

    @Before
    public void init() throws IOException {
        String path = "mybatis-config.xml";//路径
        InputStream inputStream = Resources.getResourceAsStream(path);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        sqlSession = sessionFactory.openSession();
    }

    @Test
    public void test01(){
        EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);
//        System.out.println(employeeMapper.selectByPrimaryKey(1));
//        employeeMapper.deleteByPrimaryKey(3);
        //创建 查询模板
        EmployeeExample example = new EmployeeExample();
        //添加 查询条件
        example.createCriteria().andEmpNameLike("%张%").andSalaryLessThan(new BigDecimal(20000));
        //设置 查询 查重
        example.setDistinct(true);
        //设置排序条件
        example.setOrderByClause("salary desc");
        //添加分页
        PageHelper.startPage(1,5);
        employeeMapper.selectByExample(example);
    }

}
